/**
 * 实验模板交互字段配置
 * 从 YAML 文件中提取的可交互字段的元数据
 */

export const TEMPLATE_FIELDS_CONFIG = [
  // ========== 基础信息组 ==========
  {
    group: 'basic',
    groupLabel: '基础信息',
    fields: [
      {
        path: 'name',
        label: '模板名称',
        type: 'input',
        required: true,
        placeholder: '请输入模板名称',
      },
      {
        path: 'desc',
        label: '描述',
        type: 'text',
        required: false,
        placeholder: '请输入描述',
      },
    ],
  },

  // ========== 镜像配置组 ==========
  {
    group: 'image',
    groupLabel: '镜像配置',
    fields: [
      {
        path: 'config.imagePresetId',
        label: '镜像配置',
        type: 'select-image',
        required: false,
        placeholder: '请选择镜像配置',
        desc: '选择后会自动填充镜像UID和版本UID',
      },
      {
        path: 'config.userImageUid',
        label: '用户镜像UID',
        type: 'input',
        required: true,
        placeholder: '请输入用户镜像UID',
      },
      {
        path: 'config.userImageVersionUid',
        label: '用户镜像版本UID',
        type: 'input',
        required: true,
        placeholder: '请输入用户镜像版本UID',
      },
      {
        path: 'config.engineRunUser',
        label: '运行用户ID',
        type: 'input',
        required: false,
        placeholder: '请输入运行用户ID',
      },
      {
        path: 'config.obsPresetIdForCode',
        label: 'OBS桶配置',
        type: 'select-obs',
        required: false,
        placeholder: '请选择OBS桶配置',
        desc: '选择后会自动填充代码目录前缀和桶ID',
        obsUsage: 'code', // 标记这是用于代码配置的OBS
      },
      {
        path: 'config.appUrlUserInput',
        label: '代码目录',
        type: 'split-path-input',
        required: true,
        placeholder: '请输入代码目录路径',
        prefixPath: 'config.appUrlPrefix', // 只读前缀的路径
        fullPath: 'config.appUrl', // YAML中完整路径的字段
      },
      {
        path: 'config.appUrlBucketId',
        label: '代码目录所在桶ID',
        type: 'input',
        required: true,
        placeholder: '请输入代码目录所在桶ID',
      },
      {
        path: 'config.userCommand',
        label: '执行目录',
        type: 'input',
        required: true,
        placeholder: '请输入执行目录',
      },
    ],
  },

  // ========== 动态配置组 ==========
  {
    group: 'dynamic',
    groupLabel: '动态配置',
    fields: [
      {
        path: 'config.params',
        label: '运行参数',
        type: 'keyvalue',
        required: false,
        desc: '可新增/减少运行参数',
        placeholder: {
          key: '参数键',
          value: '参数值',
        },
        // params 是对象数组，每个元素有 key, value, paramType
        isArray: true,
        arrayItemStructure: {
          key: '',
          value: '',
          paramType: 'common',
        },
      },
      {
        path: 'config.environments',
        label: '环境变量',
        type: 'keyvalue',
        required: false,
        desc: '可新增/减少环境变量',
        placeholder: {
          key: '变量名',
          value: '变量值',
        },
      },
    ],
  },

  // ========== 输出配置组 ==========
  {
    group: 'outputs',
    groupLabel: '输出配置',
    fields: [
      {
        path: 'config.obsPresetIdForOutput',
        label: 'OBS桶配置',
        type: 'select-obs',
        required: false,
        placeholder: '请选择OBS桶配置',
        desc: '选择后会自动填充训练输出数据前缀和桶ID',
        obsUsage: 'output', // 标记这是用于输出配置的OBS
      },
      {
        path: 'config.outputs[0].obsUrlUserInput',
        label: '训练输出数据',
        type: 'split-path-input',
        required: true,
        placeholder: '请输入训练输出数据路径',
        prefixPath: 'config.outputs[0].obsUrlPrefix', // 只读前缀的路径
        fullPath: 'config.outputs[0].obsUrl', // YAML中完整路径的字段
      },
      {
        path: 'config.outputs[0].obsBucketUid',
        label: '输出数据所在桶ID',
        type: 'input',
        required: true,
        placeholder: '请输入输出数据所在桶ID',
      },
    ],
  },

  // ========== 作业日志配置组 ==========
  {
    group: 'log',
    groupLabel: '作业日志配置',
    fields: [
      {
        path: 'config.obsPresetIdForLog',
        label: 'OBS桶配置',
        type: 'select-obs',
        required: false,
        placeholder: '请选择OBS桶配置',
        desc: '选择后会自动填充作业日志路径前缀和桶ID',
        obsUsage: 'log', // 标记这是用于日志配置的OBS
      },
      {
        path: 'config.logUrlUserInput',
        label: '作业日志路径',
        type: 'split-path-input',
        required: true,
        placeholder: '请输入作业日志路径',
        prefixPath: 'config.logUrlPrefix', // 只读前缀的路径
        fullPath: 'config.logUrl', // YAML中完整路径的字段
      },
      {
        path: 'config.logUrlBucketId',
        label: '日志目录所在桶ID',
        type: 'input',
        required: true,
        placeholder: '请输入日志目录所在桶ID',
      },
    ],
  },

  // ========== 资源池配置组 ==========
  {
    group: 'resource',
    groupLabel: '资源池配置',
    fields: [
      {
        path: 'config.resourcePresetId',
        label: '资源池配置',
        type: 'select-resource',
        required: false,
        placeholder: '请选择资源池配置',
        desc: '选择后会自动填充资源池相关信息',
      },
      {
        path: 'config.poolType',
        label: '资源池类型',
        type: 'input',
        required: true,
        placeholder: '请输入资源池类型',
      },
      {
        path: 'config.poolUid',
        label: '资源池UID',
        type: 'input',
        required: true,
        placeholder: '请输入资源池UID',
      },
      {
        path: 'config.specName',
        label: '资源池名称',
        type: 'input',
        required: true,
        placeholder: '请输入资源池名称',
      },
      {
        path: 'config.flavorCode',
        label: '资源池规格',
        type: 'input',
        required: true,
        placeholder: '请输入资源池规格',
      },
      {
        path: 'config.workNum',
        label: '计算节点个数',
        type: 'input',
        inputType: 'number',
        required: true,
        placeholder: '请输入计算节点个数',
        defaultValue: 1,
      },
    ],
  },

  // ========== 其他配置组 ==========
  {
    group: 'other',
    groupLabel: '其他配置',
    fields: [
      {
        path: 'config.priority',
        label: '优先级',
        type: 'radio',
        required: true,
        options: [
          { value: '1', label: '低' },
          { value: '2', label: '中' },
          { value: '3', label: '高' },
        ],
        defaultValue: '1',
      },
      {
        path: 'config.dataSources',
        label: '数据来源',
        type: 'radio',
        required: true,
        options: [
          { value: 'private', label: '私有' },
          { value: 'share', label: '共享' },
        ],
        defaultValue: 'private',
      },
    ],
  },

  // ========== 高级功能组 ==========
  {
    group: 'advanced',
    groupLabel: '高级功能',
    fields: [
      {
        path: 'config.notify',
        label: '接受作业状态变化通知',
        type: 'switch',
        required: false,
        defaultValue: 'no',
        switchValues: { on: 'yes', off: 'no' }, // 开启时为'yes', 关闭时为'no'
        desc: '开启后可接收作业状态变化通知',
      },
      {
        path: 'config.voiceNotify',
        label: '接受电话通知',
        type: 'switch',
        required: false,
        defaultValue: false,
        switchValues: { on: true, off: false },
        dependsOn: 'config.notify', // 依赖于notify字段
        dependsOnValue: 'yes', // 只有当notify为'yes'时才显示
        desc: '开启后可接收电话通知',
      },
      {
        path: 'config.annotations.faultToleranceJobUnconditionalRetry',
        label: '作业无条件重启',
        type: 'switch',
        required: false,
        defaultValue: false,
        switchValues: { on: true, off: false },
        desc: '开启后作业失败会自动重启',
      },
      {
        path: 'config.annotations.faultToleranceJobRetryEnabled',
        label: '故障自动重启',
        type: 'switch',
        required: false,
        defaultValue: false,
        switchValues: { on: true, off: false },
        desc: '开启后作业故障会自动重启',
      },
      {
        path: 'config.annotations.faultToleranceJobRetryNum',
        label: '重启次数',
        type: 'input',
        inputType: 'number',
        required: false,
        placeholder: '请输入重启次数',
        dependsOn: 'config.annotations.faultToleranceJobRetryEnabled',
        dependsOnValue: true,
        desc: '作业故障重启的最大次数',
      },
      {
        path: 'config.annotations.faultToleranceHangRetry',
        label: '作业卡死重启',
        type: 'switch',
        required: false,
        defaultValue: false,
        switchValues: { on: true, off: false },
        dependsOn: 'config.annotations.faultToleranceJobRetryEnabled',
        dependsOnValue: true,
        desc: '开启后作业卡死会自动重启',
      },
      {
        path: 'config.annotations.faultToleranceProcessRetryEnabled',
        label: '进程级故障自动重启',
        type: 'switch',
        required: false,
        defaultValue: false,
        switchValues: { on: true, off: false },
        desc: '开启后进程故障会自动重启',
      },
      {
        path: 'config.annotations.faultToleranceProcessRetryNum',
        label: '重启次数',
        type: 'select',
        required: false,
        options: [
          { value: '1', label: '1次' },
          { value: '2', label: '2次' },
          { value: '3', label: '3次' },
        ],
        defaultValue: '1',
        dependsOn: 'config.annotations.faultToleranceProcessRetryEnabled',
        dependsOnValue: true,
        desc: '进程故障重启的次数',
      },
    ],
  },

  // ========== 数据预热组 ==========
  {
    group: 'nas_warmup',
    groupLabel: '数据预热',
    fields: [
      {
        path: 'config.ext.nas.input.enable',
        label: '输入数据预热',
        type: 'switch',
        required: false,
        defaultValue: false,
        switchValues: { on: true, off: false },
        desc: '开启输入数据预热',
      },
      {
        path: 'config.ext.nas.input.nas_id',
        label: 'EFS挂载',
        type: 'select-nas',
        required: false,
        placeholder: '请选择EFS挂载',
        dependsOn: 'config.ext.nas.input.enable',
        dependsOnValue: true,
        desc: '选择EFS挂载配置',
      },
      {
        path: 'config.ext.nas.input.path',
        label: '输入路径',
        type: 'input',
        required: false,
        placeholder: '请输入S3路径',
        dependsOn: 'config.ext.nas.input.enable',
        dependsOnValue: true,
      },
      {
        path: 'config.ext.nas.output.enable',
        label: '输出数据预热',
        type: 'switch',
        required: false,
        defaultValue: false,
        switchValues: { on: true, off: false },
        desc: '开启输出数据预热',
      },
      {
        path: 'config.ext.nas.output.nas_id',
        label: 'EFS挂载',
        type: 'select-nas',
        required: false,
        placeholder: '请选择EFS挂载',
        dependsOn: 'config.ext.nas.output.enable',
        dependsOnValue: true,
        desc: '选择EFS挂载配置',
      },
      {
        path: 'config.ext.nas.output.path',
        label: '输出路径',
        type: 'input',
        required: false,
        placeholder: '请输入S3路径',
        dependsOn: 'config.ext.nas.output.enable',
        dependsOnValue: true,
      },
    ],
  },
];

/**
 * 字段分组配置（用于表单视图的卡片展示）
 */
export const FIELD_GROUPS = [
  { id: 'basic', label: '基础信息', icon: 'Document' },
  { id: 'image', label: '镜像配置', icon: 'Box' },
  { id: 'dynamic', label: '动态配置', icon: 'Plus' },
  { id: 'outputs', label: '输出配置', icon: 'Upload' },
  { id: 'log', label: '作业日志配置', icon: 'Notebook' },
  { id: 'resource', label: '资源池配置', icon: 'Monitor' },
  { id: 'other', label: '其他配置', icon: 'Setting' },
  { id: 'advanced', label: '高级功能', icon: 'Tools' },
  { id: 'nas_warmup', label: '数据预热', icon: 'Connection' },
];
